package com.example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.example.entity.Merchant;
import com.example.mapper.MerchantMapper;
import com.example.service.MerchantService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MerchantServiceImpl implements MerchantService{
     @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public boolean apply(Merchant merchant) {
        try {
            System.out.println("收到商家申请：" + merchant);
            merchantMapper.insertMerchant(merchant);
            return true;
        } catch (Exception e) {
            // 可记录日志
            e.printStackTrace(); // 打印异常信息
            return false;
        }
    }

    @Override
    public Merchant getStatus(Long aId) {
        return merchantMapper.selectByAccountId(aId);
    }

    @Override
    public boolean approve(Long mId) {
        try {
            merchantMapper.approveMerchant(mId);
            return true;
        } catch (Exception e) {
            e.printStackTrace(); // 打印异常信息
            return false;
        }
    }

    @Override
    public boolean reject(Long mId, String reason) {
        try {
            merchantMapper.rejectMerchant(mId, reason);
            return true;
        } catch (Exception e) {
            e.printStackTrace(); // 打印异常信息
            return false;
        }
    }

    @Override
    public List<Merchant> listPending() {
        return merchantMapper.selectPendingMerchants();
    }
}
